package com.testword.service.impl;

import com.testword.entity.po.Wordtable;
import com.testword.entity.query.WordtableQuery;
import com.testword.entity.query.SimplePage;
import com.testword.entity.vo.PaginationResultVO;
import com.testword.enums.PageSize;
import com.testword.mappers.WordtableMapper;
import com.testword.service.WordtableService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * Service实现
 */
@Service("wordtableService")
public class WordtableServiceImpl implements WordtableService {

	private static final Logger logger = LoggerFactory.getLogger(WordtableServiceImpl.class);

	@Resource
	private WordtableMapper<Wordtable, WordtableQuery> wordtableMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<Wordtable> findListByParam(WordtableQuery query) {
		return this.wordtableMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	public Integer findCountByParam(WordtableQuery query) {
		return this.wordtableMapper.selectCount(query);
	}

	/**
	 * 分页查询
	 */
	public PaginationResultVO<Wordtable> findListByPage(WordtableQuery query) {
		int count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE15.getSize() : query.getPageSize();

		SimplePage page = new SimplePage(query.getPageNo(), count, pageSize);
		query.setSimplePage(page);
		List<Wordtable> list = this.findListByParam(query);
		PaginationResultVO<Wordtable> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	public Integer add(Wordtable bean) {
		return this.wordtableMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<Wordtable> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.wordtableMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增/修改
	 */
	public Integer addOrUpdateBatch(List<Wordtable> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.wordtableMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 根据Id查询
	 */
	public Wordtable getWordtableById(Integer id) {
		return this.wordtableMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	public Integer updateWordtableById(Wordtable bean, Integer id) {
		return this.wordtableMapper.updateById(bean,id);
	}

	/**
	 * 根据Id删除
	 */
	public Integer deleteWordtableById(Integer id) {
		return this.wordtableMapper.deleteById(id);
	}

}
